// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso.objects;

import java.io.IOException;
import java.nio.ByteBuffer;
import zombie.Lua.LuaEventManager;
import zombie.ai.states.ThumpState;
import zombie.audio.parameters.ParameterMeleeHitSurface;
import zombie.characters.IsoGameCharacter;
import zombie.characters.IsoLivingCharacter;
import zombie.characters.IsoPlayer;
import zombie.characters.IsoZombie;
import zombie.core.Core;
import zombie.core.Rand;
import zombie.core.math.PZMath;
import zombie.core.network.ByteBufferWriter;
import zombie.core.opengl.Shader;
import zombie.core.properties.PropertyContainer;
import zombie.core.raknet.UdpConnection;
import zombie.core.textures.ColorInfo;
import zombie.inventory.types.HandWeapon;
import zombie.iso.IsoCell;
import zombie.iso.IsoDirections;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoMovingObject;
import zombie.iso.IsoObject;
import zombie.iso.IsoWorld;
import zombie.iso.RoomDef;
import zombie.iso.Vector2;
import zombie.iso.SpriteDetails.IsoFlagType;
import zombie.iso.SpriteDetails.IsoObjectType;
import zombie.iso.areas.IsoRoom;
import zombie.iso.areas.SafeHouse;
import zombie.iso.objects.interfaces.BarricadeAble;
import zombie.iso.objects.interfaces.Thumpable;
import zombie.iso.sprite.IsoSprite;
import zombie.iso.sprite.IsoSpriteInstance;
import zombie.iso.sprite.IsoSpriteManager;
import zombie.network.GameClient;
import zombie.network.GameServer;
import zombie.network.PacketTypes;
import zombie.network.ServerOptions;
import zombie.util.Type;
import zombie.vehicles.PolygonalMap2;

public class IsoWindow extends IsoObject implements BarricadeAble, Thumpable {
    public int Health = 75;
    public int MaxHealth = 75;
    public IsoWindow.WindowType type = IsoWindow.WindowType.SinglePane;
    IsoSprite closedSprite;
    IsoSprite smashedSprite;
    public boolean north = false;
    public boolean Locked = false;
    public boolean PermaLocked = false;
    public boolean open = false;
    IsoSprite openSprite;
    private boolean destroyed = false;
    private boolean glassRemoved = false;
    private IsoSprite glassRemovedSprite;
    public int OldNumPlanks;

    public IsoCurtain HasCurtains() {
        IsoGridSquare isoGridSquare = this.getOppositeSquare();
        if (isoGridSquare != null) {
            IsoCurtain isoCurtain = isoGridSquare.getCurtain(this.getNorth() ? IsoObjectType.curtainS : IsoObjectType.curtainE);
            if (isoCurtain != null) {
                return isoCurtain;
            }
        }

        return this.getSquare().getCurtain(this.getNorth() ? IsoObjectType.curtainN : IsoObjectType.curtainW);
    }

    public IsoGridSquare getIndoorSquare() {
        if (this.square.getRoom() != null) {
            return this.square;
        } else {
            if (this.north) {
                IsoGridSquare isoGridSquare0 = IsoWorld.instance.CurrentCell.getGridSquare(this.square.getX(), this.square.getY() - 1, this.square.getZ());
                if (isoGridSquare0 != null && isoGridSquare0.getRoom() != null) {
                    return isoGridSquare0;
                }
            } else {
                IsoGridSquare isoGridSquare1 = IsoWorld.instance.CurrentCell.getGridSquare(this.square.getX() - 1, this.square.getY(), this.square.getZ());
                if (isoGridSquare1 != null && isoGridSquare1.getRoom() != null) {
                    return isoGridSquare1;
                }
            }

            return null;
        }
    }

    public IsoGridSquare getAddSheetSquare(IsoGameCharacter chr) {
        if (chr != null && chr.getCurrentSquare() != null) {
            IsoGridSquare isoGridSquare0 = chr.getCurrentSquare();
            IsoGridSquare isoGridSquare1 = this.getSquare();
            if (this.north) {
                return isoGridSquare0.getY() < isoGridSquare1.getY()
                    ? this.getCell().getGridSquare(isoGridSquare1.x, isoGridSquare1.y - 1, isoGridSquare1.z)
                    : isoGridSquare1;
            } else {
                return isoGridSquare0.getX() < isoGridSquare1.getX()
                    ? this.getCell().getGridSquare(isoGridSquare1.x - 1, isoGridSquare1.y, isoGridSquare1.z)
                    : isoGridSquare1;
            }
        } else {
            return null;
        }
    }

    @Override
    public void AttackObject(IsoGameCharacter owner) {
        super.AttackObject(owner);
        IsoObject isoObject = this.square.getWall(this.north);
        if (isoObject != null) {
            isoObject.AttackObject(owner);
        }
    }

    public IsoGridSquare getInsideSquare() {
        if (this.square == null) {
            return null;
        } else {
            return this.north
                ? this.getCell().getGridSquare(this.square.getX(), this.square.getY() - 1, this.square.getZ())
                : this.getCell().getGridSquare(this.square.getX() - 1, this.square.getY(), this.square.getZ());
        }
    }

    @Override
    public IsoGridSquare getOppositeSquare() {
        return this.getInsideSquare();
    }

    public boolean isExterior() {
        IsoGridSquare isoGridSquare0 = this.getSquare();
        IsoGridSquare isoGridSquare1 = this.getOppositeSquare();
        return isoGridSquare1 == null ? false : isoGridSquare0.isInARoom() != isoGridSquare1.isInARoom();
    }

    public IsoWindow(IsoCell cell) {
        super(cell);
    }

    @Override
    public String getObjectName() {
        return "Window";
    }

    @Override
    public void WeaponHit(IsoGameCharacter owner, HandWeapon weapon) {
        IsoPlayer isoPlayer = Type.tryCastTo(owner, IsoPlayer.class);
        if (GameClient.bClient) {
            if (isoPlayer != null) {
                GameClient.instance.sendWeaponHit(isoPlayer, weapon, this);
            }
        } else {
            Thumpable thumpable = this.getThumpableFor(owner);
            if (thumpable != null) {
                if (thumpable instanceof IsoBarricade) {
                    ((IsoBarricade)thumpable).WeaponHit(owner, weapon);
                } else {
                    LuaEventManager.triggerEvent("OnWeaponHitThumpable", owner, weapon, this);
                    if (weapon == ((IsoLivingCharacter)owner).bareHands) {
                        if (isoPlayer != null) {
                            isoPlayer.setMeleeHitSurface(ParameterMeleeHitSurface.Material.Glass);
                            isoPlayer.getEmitter().playSound(weapon.getDoorHitSound(), this);
                        }
                    } else {
                        if (weapon != null) {
                            this.Damage((float)(weapon.getDoorDamage() * 5), owner);
                        } else {
                            this.Damage(100.0F, owner);
                        }

                        this.DirtySlice();
                        if (weapon != null && weapon.getDoorHitSound() != null) {
                            if (isoPlayer != null) {
                                isoPlayer.setMeleeHitSurface(ParameterMeleeHitSurface.Material.Glass);
                            }

                            owner.getEmitter().playSound(weapon.getDoorHitSound(), this);
                            if (GameServer.bServer) {
                                GameServer.PlayWorldSoundServer(owner, weapon.getDoorHitSound(), false, this.getSquare(), 1.0F, 20.0F, 2.0F, false);
                            }
                        }

                        zombie.WorldSoundManager.instance
                            .addSound(owner, this.square.getX(), this.square.getY(), this.square.getZ(), 20, 20, false, 0.0F, 15.0F);
                        if (!this.isDestroyed() && this.Health <= 0) {
                            this.smashWindow();
                            this.addBrokenGlass(owner);
                        }
                    }
                }
            }
        }
    }

    public void smashWindow(boolean bRemote, boolean doAlarm) {
        if (!this.destroyed) {
            if (GameClient.bClient && !bRemote) {
                GameClient.instance.smashWindow(this, 1);
            }

            if (!bRemote) {
                if (GameServer.bServer) {
                    GameServer.PlayWorldSoundServer("SmashWindow", false, this.square, 0.2F, 20.0F, 1.1F, true);
                } else {
                    zombie.SoundManager.instance.PlayWorldSound("SmashWindow", this.square, 0.2F, 20.0F, 1.0F, true);
                }

                zombie.WorldSoundManager.instance.addSound(null, this.square.getX(), this.square.getY(), this.square.getZ(), 10, 20, true, 4.0F, 15.0F);
            }

            this.destroyed = true;
            this.sprite = this.smashedSprite;
            if (this.getAttachedAnimSprite() != null) {
                this.getSquare().removeBlood(false, true);
                System.out.println(this.wallBloodSplats);

                for (int _int = 0; _int < this.getAttachedAnimSprite().size(); _int++) {
                    IsoSprite isoSprite = ((IsoSpriteInstance)this.getAttachedAnimSprite().get(_int)).parentSprite;
                    if (isoSprite != null && isoSprite.getProperties().Is("AttachedToGlass")) {
                        this.getAttachedAnimSprite().remove(_int);
                        _int--;
                    }
                }
            }

            this.getSquare().removeLightSwitch();
            if (doAlarm) {
                this.handleAlarm();
            }

            if (GameServer.bServer && !bRemote) {
                GameServer.smashWindow(this, 1);
            }

            this.square.InvalidateSpecialObjectPaths();
        }
    }

    public void smashWindow(boolean bRemote) {
        this.smashWindow(bRemote, true);
    }

    public void smashWindow() {
        this.smashWindow(false, true);
    }

    public void addBrokenGlass(IsoMovingObject chr) {
        if (chr != null) {
            if (this.getSquare() != null) {
                if (this.getNorth()) {
                    this.addBrokenGlass(chr.getY() >= (float)this.getSquare().getY());
                } else {
                    this.addBrokenGlass(chr.getX() >= (float)this.getSquare().getX());
                }
            }
        }
    }

    public void addBrokenGlass(boolean onOppositeSquare) {
        IsoGridSquare isoGridSquare = onOppositeSquare ? this.getOppositeSquare() : this.getSquare();
        if (isoGridSquare != null) {
            isoGridSquare.addBrokenGlass();
        }
    }

    private void handleAlarm() {
        if (!GameClient.bClient) {
            IsoGridSquare isoGridSquare = this.getIndoorSquare();
            if (isoGridSquare != null) {
                IsoRoom isoRoom = isoGridSquare.getRoom();
                RoomDef roomDef = isoRoom.def;
                if (roomDef.building.bAlarmed && !GameClient.bClient) {
                    zombie.AmbientStreamManager.instance.doAlarm(roomDef);
                }
            }
        }
    }

    public IsoWindow(IsoCell cell, IsoGridSquare gridSquare, IsoSprite gid, boolean _north) {
        gid.getProperties().UnSet(IsoFlagType.cutN);
        gid.getProperties().UnSet(IsoFlagType.cutW);
        int int0 = 0;
        if (gid.getProperties().Is("OpenTileOffset")) {
            int0 = Integer.parseInt(gid.getProperties().Val("OpenTileOffset"));
        }

        int int1 = 0;
        this.PermaLocked = gid.getProperties().Is("WindowLocked");
        if (gid.getProperties().Is("SmashedTileOffset")) {
            int1 = Integer.parseInt(gid.getProperties().Val("SmashedTileOffset"));
        }

        this.closedSprite = gid;
        if (_north) {
            this.closedSprite.getProperties().Set(IsoFlagType.cutN);
            this.closedSprite.getProperties().Set(IsoFlagType.windowN);
        } else {
            this.closedSprite.getProperties().Set(IsoFlagType.cutW);
            this.closedSprite.getProperties().Set(IsoFlagType.windowW);
        }

        this.openSprite = IsoSprite.getSprite(IsoSpriteManager.instance, gid, int0);
        this.smashedSprite = IsoSprite.getSprite(IsoSpriteManager.instance, gid, int1);
        if (this.closedSprite.getProperties().Is("GlassRemovedOffset")) {
            int int2 = Integer.parseInt(this.closedSprite.getProperties().Val("GlassRemovedOffset"));
            this.glassRemovedSprite = IsoSprite.getSprite(IsoSpriteManager.instance, this.closedSprite, int2);
        } else {
            this.glassRemovedSprite = this.smashedSprite;
        }

        if (this.smashedSprite != this.closedSprite && this.smashedSprite != null) {
            this.smashedSprite.AddProperties(this.closedSprite);
            this.smashedSprite.setType(this.closedSprite.getType());
        }

        if (this.openSprite != this.closedSprite && this.openSprite != null) {
            this.openSprite.AddProperties(this.closedSprite);
            this.openSprite.setType(this.closedSprite.getType());
        }

        if (this.glassRemovedSprite != this.closedSprite && this.glassRemovedSprite != null) {
            this.glassRemovedSprite.AddProperties(this.closedSprite);
            this.glassRemovedSprite.setType(this.closedSprite.getType());
        }

        this.sprite = this.closedSprite;
        IsoObject isoObject = gridSquare.getWall(_north);
        if (isoObject != null) {
            isoObject.rerouteCollide = this;
        }

        this.square = gridSquare;
        this.north = _north;
        switch (this.type) {
            case SinglePane:
                this.MaxHealth = this.Health = 50;
                break;
            case DoublePane:
                this.MaxHealth = this.Health = 150;
        }

        byte _byte = 69;
        if (zombie.SandboxOptions.instance.LockedHouses.getValue() == 1) {
            _byte = -1;
        } else if (zombie.SandboxOptions.instance.LockedHouses.getValue() == 2) {
            _byte = 5;
        } else if (zombie.SandboxOptions.instance.LockedHouses.getValue() == 3) {
            _byte = 10;
        } else if (zombie.SandboxOptions.instance.LockedHouses.getValue() == 4) {
            _byte = 50;
        } else if (zombie.SandboxOptions.instance.LockedHouses.getValue() == 5) {
            _byte = 60;
        } else if (zombie.SandboxOptions.instance.LockedHouses.getValue() == 6) {
            _byte = 70;
        }

        if (_byte > -1) {
            this.Locked = Rand.Next(100) < _byte;
        }
    }

    @Override
    public boolean isDestroyed() {
        return this.destroyed;
    }

    public boolean IsOpen() {
        return this.open;
    }

    @Override
    public boolean onMouseLeftClick(int x, int y) {
        return false;
    }

    @Override
    public boolean TestCollide(IsoMovingObject obj, IsoGridSquare from, IsoGridSquare to) {
        if (from == this.square) {
            if (this.north && to.getY() < from.getY()) {
                if (obj != null) {
                    obj.collideWith(this);
                }

                return true;
            }

            if (!this.north && to.getX() < from.getX()) {
                if (obj != null) {
                    obj.collideWith(this);
                }

                return true;
            }
        } else {
            if (this.north && to.getY() > from.getY()) {
                if (obj != null) {
                    obj.collideWith(this);
                }

                return true;
            }

            if (!this.north && to.getX() > from.getX()) {
                if (obj != null) {
                    obj.collideWith(this);
                }

                return true;
            }
        }

        return false;
    }

    @Override
    public IsoObject.VisionResult TestVision(IsoGridSquare from, IsoGridSquare to) {
        if (to.getZ() != from.getZ()) {
            return IsoObject.VisionResult.NoEffect;
        } else {
            if (from == this.square) {
                if (this.north && to.getY() < from.getY()) {
                    return IsoObject.VisionResult.Unblocked;
                }

                if (!this.north && to.getX() < from.getX()) {
                    return IsoObject.VisionResult.Unblocked;
                }
            } else {
                if (this.north && to.getY() > from.getY()) {
                    return IsoObject.VisionResult.Unblocked;
                }

                if (!this.north && to.getX() > from.getX()) {
                    return IsoObject.VisionResult.Unblocked;
                }
            }

            return IsoObject.VisionResult.NoEffect;
        }
    }

    @Override
    public void Thump(IsoMovingObject thumper) {
        if (thumper instanceof IsoGameCharacter) {
            Thumpable thumpable = this.getThumpableFor((IsoGameCharacter)thumper);
            if (thumpable == null) {
                return;
            }

            if (thumpable != this) {
                thumpable.Thump(thumper);
                return;
            }
        }

        if (thumper instanceof IsoZombie) {
            if (((IsoZombie)thumper).cognition == 1
                && !this.canClimbThrough((IsoZombie)thumper)
                && !this.isInvincible()
                && (!this.Locked || thumper.getCurrentSquare() != null && !thumper.getCurrentSquare().Is(IsoFlagType.exterior))) {
                this.ToggleWindow((IsoGameCharacter)thumper);
                if (this.canClimbThrough((IsoZombie)thumper)) {
                    return;
                }
            }

            int _int = ThumpState.getFastForwardDamageMultiplier();
            this.DirtySlice();
            this.Damage((float)(((IsoZombie)thumper).strength * _int), thumper);
            zombie.WorldSoundManager.instance.addSound(thumper, this.square.getX(), this.square.getY(), this.square.getZ(), 20, 20, true, 4.0F, 15.0F);
        }

        if (!this.isDestroyed() && this.Health <= 0) {
            if (this.getSquare().getBuilding() != null) {
                this.getSquare().getBuilding().forceAwake();
            }

            if (GameServer.bServer) {
                GameServer.smashWindow(this, 1);
                GameServer.PlayWorldSoundServer((IsoGameCharacter)thumper, "SmashWindow", false, thumper.getCurrentSquare(), 0.2F, 20.0F, 1.1F, true);
            }

            ((IsoGameCharacter)thumper).getEmitter().playSound("SmashWindow", this);
            zombie.WorldSoundManager.instance.addSound(null, this.square.getX(), this.square.getY(), this.square.getZ(), 10, 20, true, 4.0F, 15.0F);
            thumper.setThumpTarget(null);
            this.destroyed = true;
            this.sprite = this.smashedSprite;
            this.square.InvalidateSpecialObjectPaths();
            this.addBrokenGlass(thumper);
            if (thumper instanceof IsoZombie && this.getThumpableFor((IsoZombie)thumper) != null) {
                thumper.setThumpTarget(this.getThumpableFor((IsoZombie)thumper));
            }
        }
    }

    @Override
    public Thumpable getThumpableFor(IsoGameCharacter chr) {
        IsoBarricade isoBarricade = this.getBarricadeForCharacter(chr);
        if (isoBarricade != null) {
            return isoBarricade;
        } else if (!this.isDestroyed() && !this.IsOpen()) {
            return this;
        } else {
            isoBarricade = this.getBarricadeOppositeCharacter(chr);
            return isoBarricade != null ? isoBarricade : null;
        }
    }

    @Override
    public float getThumpCondition() {
        return (float)PZMath.clamp(this.Health, 0, this.MaxHealth) / (float)this.MaxHealth;
    }

    @Override
    public void load(ByteBuffer input, int WorldVersion, boolean IS_DEBUG_SAVE) throws IOException {
        super.load(input, WorldVersion, IS_DEBUG_SAVE);
        this.open = input.get() == 1;
        this.north = input.get() == 1;
        if (WorldVersion >= 87) {
            this.Health = input.getInt();
        } else {
            int int0 = input.getInt();
            this.Health = input.getInt();
            int int1 = input.getInt();
            if (WorldVersion >= 49) {
                short _short = input.getShort();
            } else {
                int int2 = Math.max(int1, int0 * 1000);
            }

            this.OldNumPlanks = int0;
        }

        this.Locked = input.get() == 1;
        this.PermaLocked = input.get() == 1;
        this.destroyed = input.get() == 1;
        if (WorldVersion >= 64) {
            this.glassRemoved = input.get() == 1;
            if (input.get() == 1) {
                this.openSprite = IsoSprite.getSprite(IsoSpriteManager.instance, input.getInt());
            }

            if (input.get() == 1) {
                this.closedSprite = IsoSprite.getSprite(IsoSpriteManager.instance, input.getInt());
            }

            if (input.get() == 1) {
                this.smashedSprite = IsoSprite.getSprite(IsoSpriteManager.instance, input.getInt());
            }

            if (input.get() == 1) {
                this.glassRemovedSprite = IsoSprite.getSprite(IsoSpriteManager.instance, input.getInt());
            }
        } else {
            if (input.getInt() == 1) {
                this.openSprite = IsoSprite.getSprite(IsoSpriteManager.instance, input.getInt());
            }

            if (input.getInt() == 1) {
                this.closedSprite = IsoSprite.getSprite(IsoSpriteManager.instance, input.getInt());
            }

            if (input.getInt() == 1) {
                this.smashedSprite = IsoSprite.getSprite(IsoSpriteManager.instance, input.getInt());
            }

            if (this.closedSprite != null) {
                if (this.destroyed && this.closedSprite.getProperties().Is("SmashedTileOffset")) {
                    int int3 = Integer.parseInt(this.closedSprite.getProperties().Val("SmashedTileOffset"));
                    this.closedSprite = IsoSprite.getSprite(IsoSpriteManager.instance, this.closedSprite, -int3);
                }

                if (this.closedSprite.getProperties().Is("GlassRemovedOffset")) {
                    int int4 = Integer.parseInt(this.closedSprite.getProperties().Val("GlassRemovedOffset"));
                    this.glassRemovedSprite = IsoSprite.getSprite(IsoSpriteManager.instance, this.closedSprite, int4);
                }
            }

            if (this.glassRemovedSprite == null) {
                this.glassRemovedSprite = this.smashedSprite != null ? this.smashedSprite : this.closedSprite;
            }
        }

        this.MaxHealth = input.getInt();
        if (this.closedSprite != null) {
            if (this.north) {
                this.closedSprite.getProperties().Set(IsoFlagType.cutN);
                this.closedSprite.getProperties().Set(IsoFlagType.windowN);
            } else {
                this.closedSprite.getProperties().Set(IsoFlagType.cutW);
                this.closedSprite.getProperties().Set(IsoFlagType.windowW);
            }

            if (this.smashedSprite != this.closedSprite && this.smashedSprite != null) {
                this.smashedSprite.AddProperties(this.closedSprite);
                this.smashedSprite.setType(this.closedSprite.getType());
            }

            if (this.openSprite != this.closedSprite && this.openSprite != null) {
                this.openSprite.AddProperties(this.closedSprite);
                this.openSprite.setType(this.closedSprite.getType());
            }

            if (this.glassRemovedSprite != this.closedSprite && this.glassRemovedSprite != null) {
                this.glassRemovedSprite.AddProperties(this.closedSprite);
                this.glassRemovedSprite.setType(this.closedSprite.getType());
            }
        }

        if (zombie.SystemDisabler.doObjectStateSyncEnable && GameClient.bClient) {
            GameClient.instance.objectSyncReq.putRequestLoad(this.square);
        }
    }

    @Override
    public void addToWorld() {
        super.addToWorld();
        this.getCell().addToWindowList(this);
    }

    @Override
    public void removeFromWorld() {
        super.removeFromWorld();
        this.getCell().removeFromWindowList(this);
    }

    @Override
    public void save(ByteBuffer output, boolean IS_DEBUG_SAVE) throws IOException {
        super.save(output, IS_DEBUG_SAVE);
        output.put((byte)(this.open ? 1 : 0));
        output.put((byte)(this.north ? 1 : 0));
        output.putInt(this.Health);
        output.put((byte)(this.Locked ? 1 : 0));
        output.put((byte)(this.PermaLocked ? 1 : 0));
        output.put((byte)(this.destroyed ? 1 : 0));
        output.put((byte)(this.glassRemoved ? 1 : 0));
        if (this.openSprite != null) {
            output.put((byte)1);
            output.putInt(this.openSprite.ID);
        } else {
            output.put((byte)0);
        }

        if (this.closedSprite != null) {
            output.put((byte)1);
            output.putInt(this.closedSprite.ID);
        } else {
            output.put((byte)0);
        }

        if (this.smashedSprite != null) {
            output.put((byte)1);
            output.putInt(this.smashedSprite.ID);
        } else {
            output.put((byte)0);
        }

        if (this.glassRemovedSprite != null) {
            output.put((byte)1);
            output.putInt(this.glassRemovedSprite.ID);
        } else {
            output.put((byte)0);
        }

        output.putInt(this.MaxHealth);
    }

    @Override
    public void saveState(ByteBuffer bb) throws IOException {
        bb.put((byte)(this.Locked ? 1 : 0));
    }

    @Override
    public void loadState(ByteBuffer bb) throws IOException {
        boolean _boolean = bb.get() == 1;
        if (_boolean != this.Locked) {
            this.Locked = _boolean;
        }
    }

    @Override
    public void render(float x, float y, float z, ColorInfo col, boolean bDoAttached, boolean bWallLightingPass, Shader shader) {
        super.render(x, y, z, col, bDoAttached, bWallLightingPass, shader);
    }

    public void openCloseCurtain(IsoGameCharacter chr) {
        if (chr == IsoPlayer.getInstance()) {
            Object object0 = null;
            Object object1 = null;
            IsoDirections isoDirections = IsoDirections.N;
            if (this.north) {
                IsoGridSquare isoGridSquare0 = this.square;
                isoDirections = IsoDirections.N;
                if (isoGridSquare0.getRoom() == null) {
                    isoGridSquare0 = this.getCell().getGridSquare(isoGridSquare0.getX(), isoGridSquare0.getY() - 1, isoGridSquare0.getZ());
                    isoDirections = IsoDirections.S;
                }

                object1 = object0;
                object0 = isoGridSquare0;
            } else {
                IsoGridSquare isoGridSquare1 = this.square;
                isoDirections = IsoDirections.W;
                if (isoGridSquare1.getRoom() == null) {
                    isoGridSquare1 = this.getCell().getGridSquare(isoGridSquare1.getX() - 1, isoGridSquare1.getY(), isoGridSquare1.getZ());
                    isoDirections = IsoDirections.E;
                }

                object1 = object0;
                object0 = isoGridSquare1;
            }

            if (object0 != null) {
                for (int int0 = 0; int0 < ((IsoGridSquare)object0).getSpecialObjects().size(); int0++) {
                    if (((IsoGridSquare)object0).getSpecialObjects().get(int0) instanceof IsoCurtain) {
                        ((IsoCurtain)((IsoGridSquare)object0).getSpecialObjects().get(int0)).ToggleDoorSilent();
                        return;
                    }
                }
            }

            if (object1 != null) {
                for (int int1 = 0; int1 < ((IsoGridSquare)object1).getSpecialObjects().size(); int1++) {
                    if (((IsoGridSquare)object1).getSpecialObjects().get(int1) instanceof IsoCurtain) {
                        ((IsoCurtain)((IsoGridSquare)object1).getSpecialObjects().get(int1)).ToggleDoorSilent();
                        return;
                    }
                }
            }
        }
    }

    public void removeSheet(IsoGameCharacter chr) {
        IsoGridSquare isoGridSquare0 = null;
        IsoDirections isoDirections = IsoDirections.N;
        if (this.north) {
            IsoGridSquare isoGridSquare1 = this.square;
            isoDirections = IsoDirections.N;
            if (isoGridSquare1.getRoom() == null) {
                isoGridSquare1 = this.getCell().getGridSquare(isoGridSquare1.getX(), isoGridSquare1.getY() - 1, isoGridSquare1.getZ());
                isoDirections = IsoDirections.S;
            }

            isoGridSquare0 = isoGridSquare1;
        } else {
            IsoGridSquare isoGridSquare2 = this.square;
            isoDirections = IsoDirections.W;
            if (isoGridSquare2.getRoom() == null) {
                isoGridSquare2 = this.getCell().getGridSquare(isoGridSquare2.getX() - 1, isoGridSquare2.getY(), isoGridSquare2.getZ());
                isoDirections = IsoDirections.E;
            }

            isoGridSquare0 = isoGridSquare2;
        }

        for (int _int = 0; _int < isoGridSquare0.getSpecialObjects().size(); _int++) {
            IsoObject isoObject = (IsoObject)isoGridSquare0.getSpecialObjects().get(_int);
            if (isoObject instanceof IsoCurtain) {
                isoGridSquare0.transmitRemoveItemFromSquare(isoObject);
                if (chr != null) {
                    if (GameServer.bServer) {
                        chr.sendObjectChange("addItemOfType", new Object[]{"type", isoObject.getName()});
                    } else {
                        chr.getInventory().AddItem(isoObject.getName());
                    }
                }
                break;
            }
        }
    }

    public void addSheet(IsoGameCharacter chr) {
        IsoGridSquare isoGridSquare0 = null;
        IsoObjectType isoObjectType;
        if (this.north) {
            IsoGridSquare isoGridSquare1 = this.square;
            isoObjectType = IsoObjectType.curtainN;
            if (chr != null) {
                if (chr.getY() < this.getY()) {
                    isoGridSquare1 = this.getCell().getGridSquare(isoGridSquare1.getX(), isoGridSquare1.getY() - 1, isoGridSquare1.getZ());
                    isoObjectType = IsoObjectType.curtainS;
                }
            } else if (isoGridSquare1.getRoom() == null) {
                isoGridSquare1 = this.getCell().getGridSquare(isoGridSquare1.getX(), isoGridSquare1.getY() - 1, isoGridSquare1.getZ());
                isoObjectType = IsoObjectType.curtainS;
            }

            isoGridSquare0 = isoGridSquare1;
        } else {
            IsoGridSquare isoGridSquare2 = this.square;
            isoObjectType = IsoObjectType.curtainW;
            if (chr != null) {
                if (chr.getX() < this.getX()) {
                    isoGridSquare2 = this.getCell().getGridSquare(isoGridSquare2.getX() - 1, isoGridSquare2.getY(), isoGridSquare2.getZ());
                    isoObjectType = IsoObjectType.curtainE;
                }
            } else if (isoGridSquare2.getRoom() == null) {
                isoGridSquare2 = this.getCell().getGridSquare(isoGridSquare2.getX() - 1, isoGridSquare2.getY(), isoGridSquare2.getZ());
                isoObjectType = IsoObjectType.curtainE;
            }

            isoGridSquare0 = isoGridSquare2;
        }

        if (isoGridSquare0.getCurtain(isoObjectType) == null) {
            if (isoGridSquare0 != null) {
                int _int = 16;
                if (isoObjectType == IsoObjectType.curtainE) {
                    _int++;
                }

                if (isoObjectType == IsoObjectType.curtainS) {
                    _int += 3;
                }

                if (isoObjectType == IsoObjectType.curtainN) {
                    _int += 2;
                }

                _int += 4;
                IsoCurtain isoCurtain = new IsoCurtain(this.getCell(), isoGridSquare0, "fixtures_windows_curtains_01_" + _int, this.north);
                isoGridSquare0.AddSpecialTileObject(isoCurtain);
                if (!isoCurtain.open) {
                    isoCurtain.ToggleDoorSilent();
                }

                if (GameServer.bServer) {
                    isoCurtain.transmitCompleteItemToClients();
                    if (chr != null) {
                        chr.sendObjectChange("removeOneOf", new Object[]{"type", "Sheet"});
                    }
                } else if (chr != null) {
                    chr.getInventory().RemoveOneOf("Sheet");
                }
            }
        }
    }

    public void ToggleWindow(IsoGameCharacter chr) {
        this.DirtySlice();
        IsoGridSquare.setRecalcLightTime(-1);
        if (!this.PermaLocked) {
            if (!this.destroyed) {
                if (chr == null || this.getBarricadeForCharacter(chr) == null) {
                    this.Locked = false;
                    this.open = !this.open;
                    this.sprite = this.closedSprite;
                    this.square.InvalidateSpecialObjectPaths();
                    if (this.open) {
                        if (!(chr instanceof IsoZombie) || zombie.SandboxOptions.getInstance().Lore.TriggerHouseAlarm.getValue()) {
                            this.handleAlarm();
                        }

                        this.sprite = this.openSprite;
                    }

                    this.square.RecalcProperties();
                    this.syncIsoObject(false, (byte)(this.open ? 1 : 0), null, null);
                    PolygonalMap2.instance.squareChanged(this.square);
                    LuaEventManager.triggerEvent("OnContainerUpdate");
                }
            }
        }
    }

    @Override
    public void syncIsoObjectSend(ByteBufferWriter b) {
        b.putInt(this.square.getX());
        b.putInt(this.square.getY());
        b.putInt(this.square.getZ());
        byte _byte = (byte)this.square.getObjects().indexOf(this);
        b.putByte(_byte);
        b.putByte((byte)1);
        b.putByte((byte)(this.open ? 1 : 0));
        b.putByte((byte)(this.destroyed ? 1 : 0));
        b.putByte((byte)(this.Locked ? 1 : 0));
        b.putByte((byte)(this.PermaLocked ? 1 : 0));
    }

    @Override
    public void syncIsoObject(boolean bRemote, byte val, UdpConnection source, ByteBuffer bb) {
        if (this.square == null) {
            System.out.println("ERROR: " + this.getClass().getSimpleName() + " square is null");
        } else if (this.getObjectIndex() == -1) {
            System.out
                .println(
                    "ERROR: "
                        + this.getClass().getSimpleName()
                        + " not found on square "
                        + this.square.getX()
                        + ","
                        + this.square.getY()
                        + ","
                        + this.square.getZ()
                );
        } else {
            if (GameClient.bClient && !bRemote) {
                ByteBufferWriter byteBufferWriter0 = GameClient.connection.startPacket();
                PacketTypes.PacketType.SyncIsoObject.doPacket(byteBufferWriter0);
                this.syncIsoObjectSend(byteBufferWriter0);
                PacketTypes.PacketType.SyncIsoObject.send(GameClient.connection);
            } else if (GameServer.bServer && !bRemote) {
                for (UdpConnection udpConnection0 : GameServer.udpEngine.connections) {
                    ByteBufferWriter byteBufferWriter1 = udpConnection0.startPacket();
                    PacketTypes.PacketType.SyncIsoObject.doPacket(byteBufferWriter1);
                    this.syncIsoObjectSend(byteBufferWriter1);
                    PacketTypes.PacketType.SyncIsoObject.send(udpConnection0);
                }
            } else if (bRemote) {
                boolean boolean0 = bb.get() == 1;
                boolean boolean1 = bb.get() == 1;
                boolean boolean2 = bb.get() == 1;
                if (val == 1) {
                    this.open = true;
                    this.sprite = this.openSprite;
                } else if (val == 0) {
                    this.open = false;
                    this.sprite = this.closedSprite;
                }

                if (boolean0) {
                    this.destroyed = true;
                    this.sprite = this.smashedSprite;
                }

                this.Locked = boolean1;
                this.PermaLocked = boolean2;
                if (GameServer.bServer) {
                    for (UdpConnection udpConnection1 : GameServer.udpEngine.connections) {
                        if (source != null && udpConnection1.getConnectedGUID() != source.getConnectedGUID()) {
                            ByteBufferWriter byteBufferWriter2 = udpConnection1.startPacket();
                            PacketTypes.PacketType.SyncIsoObject.doPacket(byteBufferWriter2);
                            this.syncIsoObjectSend(byteBufferWriter2);
                            PacketTypes.PacketType.SyncIsoObject.send(udpConnection1);
                        }
                    }
                }

                this.square.RecalcProperties();
                LuaEventManager.triggerEvent("OnContainerUpdate");
            }
        }
    }

    public static boolean isTopOfSheetRopeHere(IsoGridSquare sq) {
        return sq == null
            ? false
            : sq.Is(IsoFlagType.climbSheetTopN) || sq.Is(IsoFlagType.climbSheetTopS) || sq.Is(IsoFlagType.climbSheetTopW) || sq.Is(IsoFlagType.climbSheetTopE);
    }

    public static boolean isTopOfSheetRopeHere(IsoGridSquare sq, boolean _north) {
        if (sq == null) {
            return false;
        } else {
            if (_north) {
                if (sq.Is(IsoFlagType.climbSheetTopN)) {
                    return true;
                }

                if (sq.nav[IsoDirections.N.index()] != null && sq.nav[IsoDirections.N.index()].Is(IsoFlagType.climbSheetTopS)) {
                    return true;
                }
            } else {
                if (sq.Is(IsoFlagType.climbSheetTopW)) {
                    return true;
                }

                if (sq.nav[IsoDirections.W.index()] != null && sq.nav[IsoDirections.W.index()].Is(IsoFlagType.climbSheetTopE)) {
                    return true;
                }
            }

            return false;
        }
    }

    @Override
    public boolean haveSheetRope() {
        return isTopOfSheetRopeHere(this.square, this.north);
    }

    public static boolean isSheetRopeHere(IsoGridSquare sq) {
        return sq == null
            ? false
            : sq.Is(IsoFlagType.climbSheetTopW)
                || sq.Is(IsoFlagType.climbSheetTopN)
                || sq.Is(IsoFlagType.climbSheetTopE)
                || sq.Is(IsoFlagType.climbSheetTopS)
                || sq.Is(IsoFlagType.climbSheetW)
                || sq.Is(IsoFlagType.climbSheetN)
                || sq.Is(IsoFlagType.climbSheetE)
                || sq.Is(IsoFlagType.climbSheetS);
    }

    public static boolean canClimbHere(IsoGridSquare sq) {
        if (sq == null) {
            return false;
        } else if (sq.getProperties().Is(IsoFlagType.solid)) {
            return false;
        } else {
            return sq.Has(IsoObjectType.stairsBN) || sq.Has(IsoObjectType.stairsMN) || sq.Has(IsoObjectType.stairsTN)
                ? false
                : !sq.Has(IsoObjectType.stairsBW) && !sq.Has(IsoObjectType.stairsMW) && !sq.Has(IsoObjectType.stairsTW);
        }
    }

    public static int countAddSheetRope(IsoGridSquare sq, boolean _north) {
        if (isTopOfSheetRopeHere(sq, _north)) {
            return 0;
        } else {
            IsoCell isoCell = IsoWorld.instance.CurrentCell;
            if (sq.TreatAsSolidFloor()) {
                if (_north) {
                    IsoGridSquare isoGridSquare0 = isoCell.getOrCreateGridSquare((double)sq.getX(), (double)(sq.getY() - 1), (double)sq.getZ());
                    if (isoGridSquare0 == null || isoGridSquare0.TreatAsSolidFloor() || isSheetRopeHere(isoGridSquare0) || !canClimbHere(isoGridSquare0)) {
                        return 0;
                    }

                    sq = isoGridSquare0;
                } else {
                    IsoGridSquare isoGridSquare1 = isoCell.getOrCreateGridSquare((double)(sq.getX() - 1), (double)sq.getY(), (double)sq.getZ());
                    if (isoGridSquare1 == null || isoGridSquare1.TreatAsSolidFloor() || isSheetRopeHere(isoGridSquare1) || !canClimbHere(isoGridSquare1)) {
                        return 0;
                    }

                    sq = isoGridSquare1;
                }
            }

            for (int _int = 1; sq != null; _int++) {
                if (!canClimbHere(sq)) {
                    return 0;
                }

                if (sq.TreatAsSolidFloor()) {
                    return _int;
                }

                if (sq.getZ() == 0) {
                    return _int;
                }

                sq = isoCell.getOrCreateGridSquare((double)sq.getX(), (double)sq.getY(), (double)(sq.getZ() - 1));
            }

            return 0;
        }
    }

    @Override
    public int countAddSheetRope() {
        return countAddSheetRope(this.square, this.north);
    }

    public static boolean canAddSheetRope(IsoGridSquare sq, boolean _north) {
        return countAddSheetRope(sq, _north) != 0;
    }

    @Override
    public boolean canAddSheetRope() {
        return !this.canClimbThrough(null) ? false : canAddSheetRope(this.square, this.north);
    }

    @Override
    public boolean addSheetRope(IsoPlayer player, String itemType) {
        return !this.canAddSheetRope() ? false : addSheetRope(player, this.square, this.north, itemType);
    }

    public static boolean addSheetRope(IsoPlayer player, IsoGridSquare sq, boolean _north, String itemType) {
        boolean boolean0 = false;
        int _int = 0;
        byte _byte = 0;
        if (_north) {
            _byte = 1;
        }

        boolean boolean1 = false;
        boolean boolean2 = false;
        IsoGridSquare isoGridSquare0 = null;
        IsoGridSquare isoGridSquare1 = null;
        IsoCell isoCell = IsoWorld.instance.CurrentCell;
        if (sq.TreatAsSolidFloor()) {
            if (!_north) {
                isoGridSquare0 = isoCell.getGridSquare(sq.getX() - 1, sq.getY(), sq.getZ());
                if (isoGridSquare0 != null) {
                    boolean2 = true;
                    _byte = 3;
                }
            } else {
                isoGridSquare1 = isoCell.getGridSquare(sq.getX(), sq.getY() - 1, sq.getZ());
                if (isoGridSquare1 != null) {
                    boolean1 = true;
                    _byte = 4;
                }
            }
        }

        if (sq.getProperties().Is(IsoFlagType.solidfloor)) {
        }

        while (sq != null && (GameServer.bServer || player.getInventory().contains(itemType))) {
            String string = "crafted_01_" + _byte;
            if (_int > 0) {
                if (boolean2) {
                    string = "crafted_01_10";
                } else if (boolean1) {
                    string = "crafted_01_13";
                } else {
                    string = "crafted_01_" + (_byte + 8);
                }
            }

            IsoObject isoObject = new IsoObject(isoCell, sq, string);
            isoObject.setName(itemType);
            isoObject.sheetRope = true;
            sq.getObjects().add(isoObject);
            isoObject.transmitCompleteItemToClients();
            sq.haveSheetRope = true;
            if (boolean1 && _int == 0) {
                sq = isoGridSquare1;
                isoObject = new IsoObject(isoCell, isoGridSquare1, "crafted_01_5");
                isoObject.setName(itemType);
                isoObject.sheetRope = true;
                isoGridSquare1.getObjects().add(isoObject);
                isoObject.transmitCompleteItemToClients();
            }

            if (boolean2 && _int == 0) {
                sq = isoGridSquare0;
                isoObject = new IsoObject(isoCell, isoGridSquare0, "crafted_01_2");
                isoObject.setName(itemType);
                isoObject.sheetRope = true;
                isoGridSquare0.getObjects().add(isoObject);
                isoObject.transmitCompleteItemToClients();
            }

            sq.RecalcProperties();
            sq.getProperties().UnSet(IsoFlagType.solidtrans);
            if (GameServer.bServer) {
                if (_int == 0) {
                    player.sendObjectChange("removeOneOf", new Object[]{"type", "Nails"});
                }

                player.sendObjectChange("removeOneOf", new Object[]{"type", itemType});
            } else {
                if (_int == 0) {
                    player.getInventory().RemoveOneOf("Nails");
                }

                player.getInventory().RemoveOneOf(itemType);
            }

            _int++;
            if (boolean0) {
                break;
            }

            sq = isoCell.getOrCreateGridSquare((double)sq.getX(), (double)sq.getY(), (double)(sq.getZ() - 1));
            if (sq != null && sq.TreatAsSolidFloor()) {
                boolean0 = true;
            }
        }

        return true;
    }

    @Override
    public boolean removeSheetRope(IsoPlayer player) {
        return !this.haveSheetRope() ? false : removeSheetRope(player, this.square, this.north);
    }

    public static boolean removeSheetRope(IsoPlayer player, IsoGridSquare square, boolean _north) {
        if (square == null) {
            return false;
        } else {
            IsoGridSquare isoGridSquare = square;
            square.haveSheetRope = false;
            IsoFlagType isoFlagType0;
            IsoFlagType isoFlagType1;
            if (_north) {
                if (square.Is(IsoFlagType.climbSheetTopN)) {
                    isoFlagType0 = IsoFlagType.climbSheetTopN;
                    isoFlagType1 = IsoFlagType.climbSheetN;
                } else {
                    if (square.nav[IsoDirections.N.index()] == null || !square.nav[IsoDirections.N.index()].Is(IsoFlagType.climbSheetTopS)) {
                        return false;
                    }

                    isoFlagType0 = IsoFlagType.climbSheetTopS;
                    isoFlagType1 = IsoFlagType.climbSheetS;
                    String string0 = "crafted_01_4";

                    for (int int0 = 0; int0 < isoGridSquare.getObjects().size(); int0++) {
                        IsoObject isoObject0 = isoGridSquare.getObjects().get(int0);
                        if (isoObject0.sprite != null && isoObject0.sprite.getName() != null && isoObject0.sprite.getName().equals(string0)) {
                            isoGridSquare.transmitRemoveItemFromSquare(isoObject0);
                            break;
                        }
                    }

                    isoGridSquare = square.nav[IsoDirections.N.index()];
                }
            } else if (square.Is(IsoFlagType.climbSheetTopW)) {
                isoFlagType0 = IsoFlagType.climbSheetTopW;
                isoFlagType1 = IsoFlagType.climbSheetW;
            } else {
                if (square.nav[IsoDirections.W.index()] == null || !square.nav[IsoDirections.W.index()].Is(IsoFlagType.climbSheetTopE)) {
                    return false;
                }

                isoFlagType0 = IsoFlagType.climbSheetTopE;
                isoFlagType1 = IsoFlagType.climbSheetE;
                String string1 = "crafted_01_3";

                for (int int1 = 0; int1 < isoGridSquare.getObjects().size(); int1++) {
                    IsoObject isoObject1 = isoGridSquare.getObjects().get(int1);
                    if (isoObject1.sprite != null && isoObject1.sprite.getName() != null && isoObject1.sprite.getName().equals(string1)) {
                        isoGridSquare.transmitRemoveItemFromSquare(isoObject1);
                        break;
                    }
                }

                isoGridSquare = square.nav[IsoDirections.W.index()];
            }

            while (isoGridSquare != null) {
                boolean _boolean = false;

                for (int int2 = 0; int2 < isoGridSquare.getObjects().size(); int2++) {
                    IsoObject isoObject2 = isoGridSquare.getObjects().get(int2);
                    if (isoObject2.getProperties() != null && (isoObject2.getProperties().Is(isoFlagType0) || isoObject2.getProperties().Is(isoFlagType1))) {
                        isoGridSquare.transmitRemoveItemFromSquare(isoObject2);
                        if (GameServer.bServer) {
                            if (player != null) {
                                player.sendObjectChange("addItemOfType", new Object[]{"type", isoObject2.getName()});
                            }
                        } else if (player != null) {
                            player.getInventory().AddItem(isoObject2.getName());
                        }

                        _boolean = true;
                        break;
                    }
                }

                if (!_boolean || isoGridSquare.getZ() == 0) {
                    break;
                }

                isoGridSquare = isoGridSquare.getCell().getGridSquare(isoGridSquare.getX(), isoGridSquare.getY(), isoGridSquare.getZ() - 1);
            }

            return true;
        }
    }

    @Override
    public void Damage(float amount) {
        this.Damage(amount, false);
    }

    public void Damage(float amount, boolean isZombie) {
        if (!this.isInvincible() && !"Tutorial".equals(Core.GameMode)) {
            this.DirtySlice();
            this.Health = (int)((float)this.Health - amount);
            if (this.Health < 0) {
                this.Health = 0;
            }

            if (!this.isDestroyed() && this.Health == 0) {
                this.smashWindow(false, !isZombie || zombie.SandboxOptions.getInstance().Lore.TriggerHouseAlarm.getValue());
                if (this.getSquare().getBuilding() != null) {
                    this.getSquare().getBuilding().forceAwake();
                }
            }
        }
    }

    public void Damage(float amount, IsoMovingObject chr) {
        if (!this.isInvincible() && !"Tutorial".equals(Core.GameMode)) {
            this.Health = (int)((float)this.Health - amount);
            if (this.Health < 0) {
                this.Health = 0;
            }

            if (!this.isDestroyed() && this.Health == 0) {
                boolean _boolean = !(chr instanceof IsoZombie) || zombie.SandboxOptions.getInstance().Lore.TriggerHouseAlarm.getValue();
                this.smashWindow(false, _boolean);
                this.addBrokenGlass(chr);
            }
        }
    }

    public boolean isLocked() {
        return this.Locked;
    }

    public boolean isSmashed() {
        return this.destroyed;
    }

    public boolean isInvincible() {
        if (this.square != null && this.square.Is(IsoFlagType.makeWindowInvincible)) {
            int int0 = this.getObjectIndex();
            if (int0 != -1) {
                IsoObject[] isoObject0 = this.square.getObjects().getElements();
                int int1 = this.square.getObjects().size();

                for (int int2 = 0; int2 < int1; int2++) {
                    if (int2 != int0) {
                        IsoObject isoObject1 = isoObject0[int2];
                        PropertyContainer propertyContainer = isoObject1.getProperties();
                        if (propertyContainer != null
                            && propertyContainer.Is(this.getNorth() ? IsoFlagType.cutN : IsoFlagType.cutW)
                            && propertyContainer.Is(IsoFlagType.makeWindowInvincible)) {
                            return true;
                        }
                    }
                }
            }

            return this.sprite != null && this.sprite.getProperties().Is(IsoFlagType.makeWindowInvincible);
        } else {
            return false;
        }
    }

    @Override
    public IsoBarricade getBarricadeOnSameSquare() {
        return IsoBarricade.GetBarricadeOnSquare(this.square, this.north ? IsoDirections.N : IsoDirections.W);
    }

    @Override
    public IsoBarricade getBarricadeOnOppositeSquare() {
        return IsoBarricade.GetBarricadeOnSquare(this.getOppositeSquare(), this.north ? IsoDirections.S : IsoDirections.E);
    }

    @Override
    public boolean isBarricaded() {
        IsoBarricade isoBarricade = this.getBarricadeOnSameSquare();
        if (isoBarricade == null) {
            isoBarricade = this.getBarricadeOnOppositeSquare();
        }

        return isoBarricade != null;
    }

    @Override
    public boolean isBarricadeAllowed() {
        return true;
    }

    @Override
    public IsoBarricade getBarricadeForCharacter(IsoGameCharacter chr) {
        return IsoBarricade.GetBarricadeForCharacter(this, chr);
    }

    @Override
    public IsoBarricade getBarricadeOppositeCharacter(IsoGameCharacter chr) {
        return IsoBarricade.GetBarricadeOppositeCharacter(this, chr);
    }

    @Override
    public boolean getNorth() {
        return this.north;
    }

    @Override
    public Vector2 getFacingPosition(Vector2 pos) {
        if (this.square == null) {
            return pos.set(0.0F, 0.0F);
        } else {
            return this.north ? pos.set(this.getX() + 0.5F, this.getY()) : pos.set(this.getX(), this.getY() + 0.5F);
        }
    }

    public void setIsLocked(boolean lock) {
        this.Locked = lock;
    }

    public IsoSprite getOpenSprite() {
        return this.openSprite;
    }

    public void setOpenSprite(IsoSprite sprite) {
        this.openSprite = sprite;
    }

    public void setSmashed(boolean _destroyed) {
        if (_destroyed) {
            this.destroyed = true;
            this.sprite = this.smashedSprite;
        } else {
            this.destroyed = false;
            this.sprite = this.open ? this.openSprite : this.closedSprite;
            this.Health = this.MaxHealth;
        }

        this.glassRemoved = false;
    }

    public IsoSprite getSmashedSprite() {
        return this.smashedSprite;
    }

    public void setSmashedSprite(IsoSprite sprite) {
        this.smashedSprite = sprite;
    }

    public void setPermaLocked(Boolean permaLock) {
        this.PermaLocked = permaLock;
    }

    public boolean isPermaLocked() {
        return this.PermaLocked;
    }

    public static boolean canClimbThroughHelper(IsoGameCharacter chr, IsoGridSquare sq, IsoGridSquare oppositeSq, boolean _north) {
        IsoGridSquare isoGridSquare = sq;
        float float0 = 0.5F;
        float float1 = 0.5F;
        if (_north) {
            if (chr.getY() >= (float)sq.getY()) {
                isoGridSquare = oppositeSq;
                float1 = 0.7F;
            } else {
                float1 = 0.3F;
            }
        } else if (chr.getX() >= (float)sq.getX()) {
            isoGridSquare = oppositeSq;
            float0 = 0.7F;
        } else {
            float0 = 0.3F;
        }

        if (isoGridSquare == null) {
            return false;
        } else if (isoGridSquare.isSolid()) {
            return false;
        } else if (isoGridSquare.Is(IsoFlagType.water)) {
            return false;
        } else {
            return !chr.canClimbDownSheetRope(isoGridSquare)
                    && !isoGridSquare.HasStairsBelow()
                    && !PolygonalMap2.instance.canStandAt((float)isoGridSquare.x + float0, (float)isoGridSquare.y + float1, isoGridSquare.z, null, 19)
                ? !isoGridSquare.TreatAsSolidFloor()
                : !GameClient.bClient
                    || !(chr instanceof IsoPlayer)
                    || SafeHouse.isSafeHouse(isoGridSquare, ((IsoPlayer)chr).getUsername(), true) == null
                    || ServerOptions.instance.SafehouseAllowTrepass.getValue();
        }
    }

    public boolean canClimbThrough(IsoGameCharacter chr) {
        if (this.square == null || this.isInvincible()) {
            return false;
        } else if (this.isBarricaded()) {
            return false;
        } else if (chr != null && !canClimbThroughHelper(chr, this.getSquare(), this.getOppositeSquare(), this.north)) {
            return false;
        } else {
            IsoGameCharacter isoGameCharacter = this.getFirstCharacterClosing();
            if (isoGameCharacter != null && isoGameCharacter.isVariable("CloseWindowOutcome", "success")) {
                return false;
            } else {
                return this.Health > 0 && !this.destroyed ? this.open : true;
            }
        }
    }

    public IsoGameCharacter getFirstCharacterClimbingThrough() {
        IsoGameCharacter isoGameCharacter = this.getFirstCharacterClimbingThrough(this.getSquare());
        return isoGameCharacter != null ? isoGameCharacter : this.getFirstCharacterClimbingThrough(this.getOppositeSquare());
    }

    public IsoGameCharacter getFirstCharacterClimbingThrough(IsoGridSquare square) {
        if (square == null) {
            return null;
        } else {
            for (int _int = 0; _int < square.getMovingObjects().size(); _int++) {
                IsoGameCharacter isoGameCharacter = Type.tryCastTo((IsoMovingObject)square.getMovingObjects().get(_int), IsoGameCharacter.class);
                if (isoGameCharacter != null && isoGameCharacter.isClimbingThroughWindow(this)) {
                    return isoGameCharacter;
                }
            }

            return null;
        }
    }

    public IsoGameCharacter getFirstCharacterClosing() {
        IsoGameCharacter isoGameCharacter = this.getFirstCharacterClosing(this.getSquare());
        return isoGameCharacter != null ? isoGameCharacter : this.getFirstCharacterClosing(this.getOppositeSquare());
    }

    public IsoGameCharacter getFirstCharacterClosing(IsoGridSquare square) {
        if (square == null) {
            return null;
        } else {
            for (int _int = 0; _int < square.getMovingObjects().size(); _int++) {
                IsoGameCharacter isoGameCharacter = Type.tryCastTo((IsoMovingObject)square.getMovingObjects().get(_int), IsoGameCharacter.class);
                if (isoGameCharacter != null && isoGameCharacter.isClosingWindow(this)) {
                    return isoGameCharacter;
                }
            }

            return null;
        }
    }

    public boolean isGlassRemoved() {
        return this.glassRemoved;
    }

    public void setGlassRemoved(boolean removed) {
        if (this.destroyed) {
            if (removed) {
                this.sprite = this.glassRemovedSprite;
                this.glassRemoved = true;
            } else {
                this.sprite = this.smashedSprite;
                this.glassRemoved = false;
            }

            if (this.getObjectIndex() != -1) {
                PolygonalMap2.instance.squareChanged(this.square);
            }
        }
    }

    public void removeBrokenGlass() {
        if (GameClient.bClient) {
            GameClient.instance.smashWindow(this, 2);
        } else {
            this.setGlassRemoved(true);
        }
    }

    public IsoBarricade addBarricadesDebug(int numPlanks, boolean metal) {
        IsoGridSquare isoGridSquare = this.square.getRoom() == null ? this.square : this.getOppositeSquare();
        boolean _boolean = isoGridSquare != this.square;
        IsoBarricade isoBarricade = IsoBarricade.AddBarricadeToObject(this, _boolean);
        if (isoBarricade != null) {
            for (int _int = 0; _int < numPlanks; _int++) {
                if (metal) {
                    isoBarricade.addMetalBar(null, null);
                } else {
                    isoBarricade.addPlank(null, null);
                }
            }
        }

        return isoBarricade;
    }

    public void addRandomBarricades() {
        IsoGridSquare isoGridSquare = this.square.getRoom() == null ? this.square : this.getOppositeSquare();
        if (this.getZ() == 0.0F && isoGridSquare != null && isoGridSquare.getRoom() == null) {
            boolean _boolean = isoGridSquare != this.square;
            IsoBarricade isoBarricade = IsoBarricade.AddBarricadeToObject(this, _boolean);
            if (isoBarricade != null) {
                int int0 = Rand.Next(1, 4);

                for (int int1 = 0; int1 < int0; int1++) {
                    isoBarricade.addPlank(null, null);
                }

                if (GameServer.bServer) {
                    isoBarricade.transmitCompleteItemToClients();
                }
            }
        } else {
            this.addSheet(null);
            this.HasCurtains().ToggleDoor(null);
        }
    }

    public static enum WindowType {
        SinglePane,
        DoublePane;
    }
}
